<?php
class Zend_View_Helper_IsAllowed extends Zend_View_Helper_Abstract
{
	protected $_acl;
	protected $_user;

	public function IsAllowed($resource = null, $privelege = null)
	{
		return (bool) $this->getAcl()->isAllowed($this->getUser(), $resource, $privelege);
	}

	/**
	 * @return App_Model_Acl
	 */
	public function getAcl()
	{
		if (null === $this->_acl) {
			$this->setAcl(App_Model_Acl::getInstance());
		}
		return $this->_acl;
	}

	/**
	 * @return App_View_Helper_IsAllowed
	 */
	public function setAcl(Zend_Acl $acl)
	{
		$this->_acl = $acl;
		return $this;
	}

	/**
	 * @return Users_Model_User
	 */
	public function getUser()
	{
		if (null === $this->_user) {
			$this->setUser(Smapp::getCurrentUser());
		}
		return $this->_user;
	}

	/**
	 * @return App_View_Helper_IsAllowed
	 */
	public function setUser(Users_Model_User $user)
	{
		$this->_user = $user;
		return $this;
	}

}